package cz.mpelant.msoe.mealchecker.parser;

import java.util.Scanner;
import java.util.regex.MatchResult;
import java.util.regex.Pattern;

public class Parser {
	protected static String nonTag = "[^<]*";
	protected static String td = nonTag + "<td[^>]*>";
	protected static String tr = nonTag + "<tr[^>]*>";
	protected static String tdEnd = nonTag + "</td>";
	protected static String trEnd = nonTag + "</tr>";
	protected static String a = nonTag + "<a[^>]*>";
	protected static String aEnd = nonTag + "</a>";
	protected static String value = "([^<]+)";

	public static String getData(String source) {
		return getMatch(
				source,
				Pattern.compile("<!-- This is where the Main data will start. DO NOT PUT ANYTHING AFTER THIS -->(.*)<!-- This is where the Main data will end. DO NOT PUT ANYTHING BEFORE THIS -->",
						Pattern.MULTILINE | Pattern.DOTALL)).group(1);
	}

	protected static MatchResult getMatch(String source, Pattern pattern) {
		Scanner s = new Scanner(source);
		s.findWithinHorizon(pattern, 0);
		MatchResult result = s.match();
		return result;
	}
}
